package com.zzyl.serve.service.impl;

import java.util.List;
import com.zzyl.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.zzyl.serve.mapper.NursingProjectMapper;
import com.zzyl.serve.domain.NursingProject;
import com.zzyl.serve.service.INursingProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

/**
 * 护理项目Service业务层处理
 *
 * @author ruoyi
 * @date 2024-09-30
 */
@Service
@Slf4j
public class NursingProjectServiceImpl extends ServiceImpl<NursingProjectMapper, NursingProject> implements INursingProjectService
{
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 查询护理项目
     *
     * @param id 护理项目主键
     * @return 护理项目
     */
    @Override
    @Cacheable(cacheNames = "nursingProject",key ="#id")
    public NursingProject selectNursingProjectById(Long id)
    {
        return getById(id);
    }

    /**
     * 查询护理项目列表
     *
     * @param nursingProject 护理项目
     * @return 护理项目
     */
    @Override
    public List<NursingProject> selectNursingProjectList(NursingProject nursingProject)
    {
        return nursingProjectMapper.selectNursingProjectList(nursingProject);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProject 护理项目
     * @return 结果
     */
    @Override
    @Transactional
    @CacheEvict(cacheNames = "nursingProject", allEntries = true)
    public int insertNursingProject(NursingProject nursingProject)
    {
        //设置创建时间
        nursingProject.setCreateTime(DateUtils.getNowDate());
        //调用nursingProjectMapper的insertNursingProject方法插入数据
        int flag = nursingProjectMapper.insertNursingProject(nursingProject);
        // 返回插入结果
        return flag;
    }

    /**
     * 修改护理项目
     *
     * @param nursingProject 护理项目
     * @return 结果
     */
    @Override
    @Transactional
    @CacheEvict(cacheNames = "nursingProject", allEntries = true)
    public int updateNursingProject(NursingProject nursingProject)
    {
        //设置创建时间
        nursingProject.setUpdateTime(DateUtils.getNowDate());
        //调用Mapper的update方法插入数据
        int flag = nursingProjectMapper.updateNursingProject(nursingProject);
        // 返回插入结果
        return flag;
    }

    /**
     * 批量删除护理项目
     *
     * @param ids 需要删除的护理项目主键
     * @return 结果
     */
    @Override
    @Transactional
    @CacheEvict(cacheNames = "nursingProject", allEntries = true)
    public int deleteNursingProjectByIds(Long[] ids)
    {
        //调用Mapper的deleteNursingProjectByIds方法插入数据
        int flag = nursingProjectMapper.deleteNursingProjectByIds(ids);
        // 返回插入结果
        return flag;
    }

    /**
     * 删除护理项目信息
     *
     * @param id 护理项目主键
     * @return 结果
     */
    @Override
    @Transactional
    @CacheEvict(cacheNames = "nursingProject", allEntries = true)
    public int deleteNursingProjectById(Long id)
    {
        //调用Mapper的deleteNursingProjectById方法插入数据
        int flag = nursingProjectMapper.deleteNursingProjectById(id);
        // 返回插入结果
        return flag;
    }
}
